
const otxt = document.getElementById("txt")
const olist = document.getElementById("list")

const url = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su";

otxt.oninput = function(){
    if(this.value === ""){
        olist.innerHTML = "";
        return;
        
    }   
    const str = `wd=${this.value}&cb=yitiaoshuju`;
    const script = document.createElement("script");
    script.src = url + "?" + str;
    document.body.appendChild(script);
    window.yitiaoshuju = function(res){
        let str = "";
        for(let i=0;i<res.s.length;i++){
            str += `<li>${res.s[i]}</li>`
        }
        olist.innerHTML = str;
    }
}


// 轮播图

function Banner(index){
    this.left = document.getElementById("left");
    this.right = document.getElementById("right");
    this.banner_box = document.querySelector("#banner_box");
    this.imgs = this.banner_box.children;
    this.index = index;
    this.banner_box.style.width = this.imgs.length * this.imgs[0].offsetWidth + "px";
    this.banner_box.style.left = this.index * -this.imgs[0].offsetWidth + "px";
    this.addEvent();
}
Banner.prototype = {
    constructor:Banner,
    addEvent:function(){
        const that = this;
        this.left.onclick = function(){
            that.changeIndexLeft()
        }
        this.right.onclick = function(){
            that.changeIndexRight()
        }
    },
    changeIndexLeft:function(){
        if(this.index===0){
            this.index=this.imgs.length-2
                this.banner_box.style.left =-(this.imgs.length-1)*this.imgs[0].offsetWidth+"px"
            }else{
            this.index--;}
        this.changePos();
    },

    changeIndexRight:function(){
        if(this.index === this.imgs.length-1){
            this.index = 1;
            this.banner_box.style.left = 0;
        }else{
            this.index++;
        }
        this.changePos();
    },

    changePos:function(){
        move(this.banner_box, {
            left: -this.index * this.imgs[0].offsetWidth
        })
    }
}
// console.log(1)
    new Banner(1);

    function move(ele, data, callback){
    clearInterval(ele.t);
    ele.t = setInterval(() => {
        let flag = true;
        for(let i in data){
            let now = parseInt(getStyle(ele, i));
            let speed = (data[i] - now) / 7;
            speed = speed < 0 ? Math.floor(speed) : Math.ceil(speed);
            ele.style[i] = now + speed + "px";
            if(data[i] !== now) flag = false;
        }
        if(flag){
            clearInterval(ele.t)
            callback && callback();
        }
    }, 30);
    }
    function getStyle(ele, attr){
    return getComputedStyle ? getComputedStyle(ele)[attr] : ele.currentStyle[attr];
    }


    // 三级菜单栏

    $(function(){
    
        $(".banner-list").find("li").hover(function(){
            $(this).children("ul").show();
        },function(){
            $(this).children("ul").hide();
        })

    })


    // 楼层
    

    